<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/public/inc/tags.jsp"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <jsp:include page="/public/inc/head.jsp"/>
    <%--<script type="text/javascript">
        var $table;
        //初始化bootstrap-table的内容
        $(function () {
            //记录页面bootstrap-table全局变量$table，方便应用
            var queryUrl = '/system/wwdx_book/json/list?rnd=' + Math.random();
            queryUrl = "";
            $table = $('#bookTable').bootstrapTable({
                url: queryUrl,                      //请求后台的URL（*）
                method: 'GET',                      //请求方式（*）
                //toolbar: '#toolbar',              //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                smartDisplay:true,
                sortStable: true,                     //是否启用排序
                sortOrder: "desc",                   //排序方式
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                      //是否显示表格搜索
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列（选择显示的列）
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                //height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "id",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                  //是否显示父子表
                //得到查询的参数
                queryParams : function (params) {
                    //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    return {
                        rows: params.limit,                         //页面大小
                        page: (params.offset / params.limit) + 1,   //页码
                        sort: params.sort,      //排序列名  
                        sortOrder: params.order //排位命令（desc，asc） 
                    };
                },
                columns: [{
                    title : '序号',
                    align: "center",
                    width: 40,
                    formatter: function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $table.bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页  
                        var pageNumber = $table.bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                }, {
                    field: 'bookname',
                    title: '书籍名称'
                }, {
                    field: 'click_count',
                    title: '点击量',
                    sortable: true
                }, {
                    field:'id',
                    title: '操作',
                    width: 120,
                    align: 'center',
                    valign: 'middle',
                    formatter: actionFormatter
                }],
                onLoadSuccess: function () {
                },
                onLoadError: function () {
                    alert("数据加载失败！");
                },
                onDblClickRow: function (row, $element) {
                    var id = row.id;
                    //EditViewById(id, 'view');
                }
            });
        });
        
        //操作栏的格式化
        function actionFormatter(value, row, index) {
            var id = value;
            var result = "";
            result += "<a href='javascript:;' class='btn btn-xs green' onclick=\"EditViewById('" + id + "', view='view')\" title='查看'><span class='glyphicon glyphicon-search'></span></a>";
            result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"EditViewById('" + id + "')\" title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
            result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"DeleteByIds('" + id + "')\" title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
            return result;
        }
    </script>--%>
</head>
<body>
<div id="header" class="navbar navbar-static-top" role="navigation">
    <jsp:include page="/public/inc/top.jsp"/>
</div>
<div class="container-fluid" style="margin-top:5px;margin-bottom:60px;">
    <div class="row">
        <jsp:include page="/public/inc/menu.jsp"/>
        <div class="col-xs-12 col-sm-10">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <div class="media">
                        <div class="media-body">
                            <span class="glyphicon glyphicon-list"></span>书籍管理
                        </div>
                        <div class="media-right">
                            <a href="/system/wwdx_book/create" class="btn btn-primary">
                                <span class="glyphicon glyphicon-plus"></span>书籍添加
                            </a>
                        </div>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="form-inline">
                        <form action="/system/wwdx_book/list">
                            <input type="hidden" name="phase" value="${phase}">
                            <input type="hidden" name="pid" value="${pid}">
                            <label>
                                <select name="type" class="form-control">
                                    <option value="">类型</option>
                                    <option value="0" <c:if test="${type==0}"> selected="selected"</c:if>>书籍</option>
                                    <option value="1" <c:if test="${type==1}"> selected="selected"</c:if>>小课</option>
                                </select>
                            </label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <label>
                                <select name="status" class="form-control">
                                    <option value="">是否上线</option>
                                    <option value="1" <c:if test="${status eq 1}">selected</c:if>>否</option>
                                    <option value="0" <c:if test="${status eq 0}">selected</c:if>>是</option>
                                </select>
                            </label>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            编号: <input type="text" class="form-control" name="bookid" placeholder="编号"/>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            书名: <input type="text" class="form-control" name="bookname" placeholder="书名"/>
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <button type="submit" class="btn btn-primary">筛选</button>
                        </form>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>封面</th>
                            <th>编号</th>
                            <th>名称</th>
                            <th>类型</th>
                            <th>启用</th>
                           <%-- <th>所属分类</th>
                            <th>所属标签</th>--%>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach var="l" items="${list}" varStatus="status">
                            <tr>
                                <td>
                                        ${status.count}
                                </td>
                                <td>
                                    <img src="http://img.readerday.com/cover/${l.bookimg}" style="height: 70px;width: 70px;">
                                </td>
                                <td>
                                        ${l.bookid}
                                </td>
                                <td>
                                        ${l.bookname}
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.type eq 0 }">
                                            <span class="btn btn-primary btn-xs">书籍</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="btn btn-danger btn-xs">小课</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <td>
                                    <c:choose>
                                        <c:when test="${l.status eq 0 }">
                                            <span class="btn btn-primary btn-xs">是</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="btn btn-danger btn-xs">否</span>
                                        </c:otherwise>
                                    </c:choose>
                                </td>
                                <%--<td>
                                    <c:if test="${fn:length(l.classes) ne 2}">
                                        <span class="btn btn-success btn-xs">${l.classes}</span>
                                    </c:if>
                                </td>
                                <td>
                                    <c:if test="${fn:length(l.tabs) ne 2}">
                                        <span class="btn btn-warning btn-xs">${l.tabs}</span>
                                    </c:if>
                                </td>--%>
                                <td>
                                    <a class="btn btn-primary btn-xs"
                                       href="/system/wwdx_banner/create?id=${l.bookid}">
                                        <span class="glyphicon glyphicon-heart"></span> 推荐首页
                                    </a>
                                    <c:if test="${phase ne null && phase ne ''}">
                                        <a class="btn btn-primary btn-xs"
                                           href="/system/wwdx_book/addgiveonebook?phase=${phase}&bookid=${l.bookid}">
                                            <span class="glyphicon glyphicon-plus"></span> 赠一得一
                                        </a>
                                    </c:if>
                                    <a class="btn btn-primary btn-xs"
                                       href="/system/wwdx_book/addbookonline?bookid=${l.bookid}">
                                        <span class="glyphicon glyphicon-plus"></span> 每日上新
                                    </a>
                                    <%--<c:if test="${pid ne null && pid ne ''}">
                                        <a class="btn btn-primary btn-xs"
                                           href="/system/wwdx_book_classify/save?bookid=${l.bookid}&pid=${pid}&type=2">
                                            <span class="glyphicon glyphicon-plus"></span> 书籍分类
                                        </a>
                                    </c:if>--%>
                                    <%--<a class="btn btn-primary btn-xs"
                                       href="/system/wwdx_book/addnovice?bookid=${l.bookid}">
                                        <span class="glyphicon glyphicon-plus"></span> 新手专区
                                    </a>--%>
                                    <%--<a class="btn btn-primary btn-xs"
                                       href="/system/wwdx_book/createCDKEY?bookid=${l.bookid}">
                                        <span class="glyphicon glyphicon-plus"></span> 兑换码
                                    </a>--%>
                                    <a class="btn btn-primary btn-xs"
                                       href="/system/wwdx_book/chapter_list?bookid=${l.bookid}">
                                        <span class="glyphicon glyphicon-search"></span>查看章节
                                    </a>
                                    <a class="btn btn-primary btn-xs"
                                       href="/system/wwdx_book/edit?id=${l.id}">
                                        <span class="glyphicon glyphicon-pencil"></span>修改
                                    </a>
                                    <a class="btn btn-danger btn-xs" onclick="del('${l.id}');">
                                        <span class="glyphicon glyphicon-trash"></span> 删除
                                    </a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
                <div class="panel-footer">
                    <p:pagination url="/system/wwdx_book/list" total="${listSize}"/>
                </div>
            </div>
        </div>
    </div>
</div>
<jsp:include page="/public/inc/bottom.jsp"/>
</body>
</html>
<script type="text/javascript">
    function del(id) {
        var msg = "您确认要删除吗？";
        if (window.confirm(msg)) {
            window.location.href = "/system/wwdx_book/delete?id=" + id;
        }
    }
</script>